package craky.keeper.skin;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.border.EmptyBorder;

import craky.component.JImagePane;
import craky.componentc.JCButton;
import craky.keeper.util.KeeperUtil;
import craky.util.UIUtil;

public class DeleteConfirmPane extends JImagePane {
	private static final long serialVersionUID = 8218959983027142762L;
	private static final Image BG_IMAGE = KeeperUtil
			.getImage("skin_list_bg.png");

	private AlphaComposite COMPOSITE = AlphaComposite.SrcOver.derive(0.75F);
	private SkinMgr skinMgr;
	private JLabel lbInfo;
	private JCButton btnOk;
	private JCButton btnCancel;
	private Skin skin;

	public DeleteConfirmPane(SkinMgr skinMgr) {
		this.skinMgr = skinMgr;
		this.lbInfo = new JLabel("您确定要删除这个皮肤吗？");
		this.btnOk = new JCButton();
		this.btnCancel = new JCButton();
		initUI();
	}

	private void initUI() {
		setImageOnly(true);
		setLayout(null);
		setBorder(new EmptyBorder(0, 0, 0, 0));
		this.lbInfo.setBounds(22, 17, 200, 15);
		this.lbInfo.setOpaque(false);
		this.lbInfo.setForeground(new Color(253, 253, 253));
		this.lbInfo.setBorder(new EmptyBorder(0, 0, 0, 0));
		this.lbInfo.setFont(new Font("宋体", 0, 12));
		this.lbInfo.setHorizontalAlignment(2);
		this.lbInfo.setVerticalAlignment(1);
		this.btnOk.setBounds(81, 61, 65, 21);
		this.btnOk.setFocusable(false);
		this.btnOk.putClientProperty("EventKey", "DelSkinOK");
		this.btnOk.setImage(KeeperUtil.getImage("skin_del_ok.png", true));
		this.btnOk.setRolloverImage(KeeperUtil.getImage(
				"skin_del_ok_rollover.png", true));
		this.btnOk.setPressedImage(this.btnOk.getRolloverImage());
		this.btnOk.addActionListener(this.skinMgr);
		this.btnCancel.setBounds(158, 61, 65, 21);
		this.btnCancel.setFocusable(false);
		this.btnCancel.putClientProperty("EventKey", "DelSkinCancel");
		this.btnCancel.setImage(KeeperUtil
				.getImage("skin_del_cancel.png", true));
		this.btnCancel.setRolloverImage(KeeperUtil.getImage(
				"skin_del_cancel_rollover.png", true));
		this.btnCancel.setPressedImage(this.btnCancel.getRolloverImage());
		this.btnCancel.addActionListener(this.skinMgr);
		add(this.lbInfo);
		add(this.btnOk);
		add(this.btnCancel);
	}

	public void updateBackground(Skin skin, JComponent sameAs) {
		this.skin = skin;
		BufferedImage image = UIUtil
				.getGraphicsConfiguration(this)
				.createCompatibleImage(sameAs.getWidth(), sameAs.getHeight(), 3);
		Graphics2D imageG = image.createGraphics();
		sameAs.paint(imageG);
		imageG.setComposite(this.COMPOSITE);
		imageG.drawImage(BG_IMAGE, 2, 2, null);
		imageG.dispose();
		setImage(image);
	}

	public Skin getSkin() {
		return this.skin;
	}
}